home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / coreaids.zip / SCAN_BYT.ASM < prev    next >
Assembly Source File  |  1987-06-25  |  3KB  |  92 lines

  1. ;    DESC:    Scans a source buffer for given characters           V1.01
  2. ;        and returns the character and location of the closest
  3. ;        matching character
  4. ;
  5. ;    ***    SCAN_BYT performs forward and reverse searches. The CLD
  6. ;        assembler command must be used before calling the procedure
  7. ;        to perform a forward search. The STD command must be used
  8. ;        before calling to perform a reverse search.     ***
  9. ;
  10. ;    IN:    *{MATCH2N} 2nd and additional matches
  11. ;        *{SEG_VAL} segment and
  12. ;        *{OFFSET} offset of buffer to scan
  13. ;        *{MATCH1} 1st of N number of possible matching sequences
  14. ;        *{N} number of matching sequences passed in
  15. ;    OUT:    *{MATCH_VAL} value of matching character
  16. ;        *{MATCH_LOC} location of offset in match segment where
  17. ;         matching value was found
  18. ;    SAMPLE:    Callm    SCAN_BYT,<MATCH2N,SEG_VAL,OFFSET,MATCH1,N>,
  19. ;                         <MATCH_VAL,MATCH_LOC>
  20. ;    ##################################################################
  21.  
  22.     Extrn    PUSHALL:Near
  23.     Extrn    POPALL:Near
  24.  
  25. SCAN_BYC    Segment
  26.     Assume    CS:SCAN_BYC
  27.     Public    SCAN_BYT
  28.  
  29.                         ;notice.
  30.     DB    'SCAN_BYT - V1.01, Copyright 1987, CoreTechs   ',0DH,0AH
  31.  
  32. SCAN_BYT    Proc    Near
  33.  
  34.     Call    PUSHALL
  35.     Pop    BX                ;recover the number of
  36.                         ;Possible matches.
  37.     Pop    AX                ;recover one possible match.
  38.     Pop    SI                ;recover offset of buffer.
  39.     Pop    ES                ;recover segment of buffer.
  40.  
  41.     Push    AX                ;replace match on stack.
  42.     Mov    DX,0FFFFH            ;init. scan to buffer end.
  43.  
  44.     Pushf                    ;determine direction of scan.
  45.     Pop    BP
  46.     And    BP,0400H            ;strip out direction bit.
  47.     Jz    TOP                ;if forward scan,ok.
  48.     Mov    DX,0                ;else, reset scanlo.
  49.  
  50. TOP:    Mov    DI,SI                ;start scan at buffer start.
  51.     Mov    CX,0FFFFH            ;set repeat code to search
  52.                         ;entire segment.
  53.     Pop    AX                ;get match.
  54.     Repnz    SCASB                ;scan for match.
  55.  
  56.     Pushf                    ;determine direction of scan.
  57.     Pop    BP
  58.     And    BP,0400H            ;strip out direction bit.
  59.     Jnz    DECR
  60.     Dec    DI                ;if up, then decrement DI
  61.     Jmp    INCR
  62. DECR:    Inc    DI                ;if down, the increment DI.
  63.  
  64.     Cmp    DI,DX                ;find nearest point in buffer.
  65.     Jb    S1                ;if not nearest, ignore.
  66.  
  67.     Cmp    DI,SI                ;must be before buffer start.
  68.     Jg    S1                ;if not before buffer, ignore.
  69.     Jmp    S2                ;if acceptable,set new point.
  70.  
  71. INCR:    Cmp    DI,DX                ;find nearest point in buffer.
  72.     Jae    S1                ;if not nearest, ignore.
  73.  
  74.     Cmp    DI,SI                ;must be past buffer start.
  75.     Jb    S1                ;if not past BOB, ignore.
  76.  
  77. S2:    Mov    DX,DI                ;save location of match.
  78.     Mov    CS:WORD PTR[0],AX        ;save match value.
  79.  
  80. S1:    Dec    BX                ;are there any more matches?
  81.     Jz    DONE                ;if not, return.
  82.     Jmp    TOP                ;if yes, handle other matches.
  83.  
  84. DONE:    Push    DX                ;return with location of match
  85.     Push    CS:WORD PTR[0]            ;and matching character.
  86.     Call    POPALL
  87.     Ret
  88.  
  89. SCAN_BYT    Endp
  90. SCAN_BYC    Ends
  91.     End
  92.